
// OSDAppChooserDlg.h : header file
//
// 
// Copyright (c) Jason Sandys, 2009
//
// License: This code is released according to the 
// Microsoft Public License (Ms-PL) as documented at 
// http://osdappchooser.codeplex.com/license
//
//////////////////////////////////////////////////////////////////////

#pragma once

#include "AppChooserXMLConfigFile.h"
#include "ConfigMgrLogFile.h"
#include "HTMLControls\XHTMLTree.h"
#include "HTMLControls\XHTMLStatic.h"
#include "ResizeDlg.h"
#include "DialogHeader.h"
#include "CmdLineParser.h"
#include "afxwin.h"
#include "afxcmn.h"

#define CMDLINE_DEFAULTAPPSET _T ("appset")
#define CMDLINE_TSVARNAME _T ("var")
#define CMDLINE_CONFIGFILENAME _T ("conf")
#define DEFAULT_TSVARNAME _T ("OSDAppTreeApps")

#define TREEICON_GROUP		0
#define TREEICON_APP		2
#define TREEICON_LINKEDAPP	4

#define MINWIDTH 300
#define MINHEIGHT 300

// COSDAppChooserDlg dialog
//************************************************************
/**
<summary>Specializes the CDialog class to create the main 
dialog window for the application.</summary>
<remark>Note that COM is initialized by the 
CjAppChooserXMLConfigFile class which is instantiated by the
m_xmlConfig member variable.</remark>
*/
//************************************************************
class COSDAppChooserDlg : public CResizeDlg
{
	friend class CjAppChooserXMLConfigFile;

// Construction
public:
	COSDAppChooserDlg(CjConfigMgrLogFile& logFile, ITSEnvClassPtr& tsEnv, CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_OSDAPPCHOOSER_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support

	typedef struct _APPDATA
	{
		CString id;
		bool mandatory;
		bool prevSelect;
		bool toolTipSet;
		CStringList reqAppsList;
		CStringList depAppsList;
		GUIDSet currentDepApps;

		_APPDATA() : mandatory(false), prevSelect(false), toolTipSet(false) {};

	} APPDATA;

	typedef CTypedPtrList<CPtrList, APPDATA*> APPDATALIST;
	typedef CTypedPtrMap<CMapStringToPtr, CString, HTREEITEM> APPTREEMAP;

// Implementation
protected:
	HICON m_hIcon;
	HICON m_hCustomIcon;

   	///<summary>Reference to the open log file</summary>
	CjConfigMgrLogFile& m_logFile;				
    
   	///<summary>Reference to Task Sequence Environment COM object</summary>
    ITSEnvClassPtr& m_tsEnv;

    ///<summary>Used to load and access the XML configuration file</summary>
	CjAppChooserXMLConfigFile m_xmlConfig;				
	
	///<summary>The image list for tree images</summary>
	CImageList m_imageList;

	///<summary>Parses and queries the command-line</summary>
	CCmdLineParser m_cmdLine;

	CDialogHeader m_HeaderCtrl;

	APPDATALIST m_appData;
	APPTREEMAP m_appTreeMap;

	void PopulateAppSets(LPCTSTR lpszDefAppSet = 0);
	void SelectAppSet(LPCTSTR lpszAppSet);
	void SetInfoText (DWORD dwID, ...);
	void SetToolTip(HTREEITEM hItem, PCTSTR pAppName = 0, PCTSTR pIcon = 0, PCTSTR pAppInfo = 0);
	void AddTooltipApps(CString& tooltip, const CStringList& appList, PCTSTR pHeading);

	HTREEITEM AddItem(PCTSTR pName, HTREEITEM hParent, bool bDefault = false, bool bMandatory = false, PCTSTR appID = 0);

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	
	DECLARE_MESSAGE_MAP()
	CButton m_ctrlOK;
	CStatic m_ctrlAppSetPrompt;
	CComboBox m_ctrlAppSets;
	CXHtmlTree m_ctrlApps;
	CStatic m_ctrlInfo;

public:
	afx_msg void OnCbnSelchangeAppset();
	afx_msg void OnBnClickedOk();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnSizing(UINT fwSide, LPRECT pRect);
	afx_msg LRESULT OnCheckbox(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnCheck(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnTooltip(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnTooltipInit(WPARAM wParam, LPARAM lParam);
	virtual BOOL DestroyWindow();
};
